{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "aa8f782e",
   "metadata": {},
   "source": [
    "-----\n",
    "*时间：2022.10.18\n",
    "*记录人：陈雯慧\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf37a4da",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. while循环\n",
    "> 2. 购物车练习\n",
    "> 3. 元组_集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3a781975",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙 0\n",
      "你是风儿我是沙 1\n",
      "你是风儿我是沙 2\n",
      "你是风儿我是沙 3\n",
      "你是风儿我是沙 4\n",
      "你是风儿我是沙 5\n",
      "你是风儿我是沙 6\n",
      "你是风儿我是沙 7\n",
      "你是风儿我是沙 8\n",
      "你是风儿我是沙 9\n"
     ]
    }
   ],
   "source": [
    "# while true 可以实现 for + range 的方法\n",
    "#while true 一般用于不确定的循环次数或者无限次循环操作\n",
    "count=0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙\",count)\n",
    "    count +=1\n",
    "    if count==10:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ba77df5b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card：········\n",
      "游戏开始了\n",
      "guess_digit:1\n",
      "往大了猜\n",
      "guess_digit:11\n",
      "往小了猜一下\n",
      "guess_digit:9\n",
      "往大了猜\n",
      "guess_digit:10\n",
      "yes,you got it.\n"
     ]
    }
   ],
   "source": [
    "#猜数字小游戏： 0<n<100,5次机会猜游戏，每次猜完出题人提示 你猜的有点大/有点小\n",
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card：\"))\n",
    "count=0\n",
    "#print(hide_card)\n",
    "if hide_card<100 and hide_card>0 :\n",
    "    print(\"游戏开始了\")\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_digit= int(input(\"guess_digit:\"))#玩游戏的人\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes,you got it.\")\n",
    "                break \n",
    "            elif guess_digit > hide_card:\n",
    "                    print(\"往小了猜一下\")\n",
    "            else:\n",
    "                    print(\"往大了猜\")\n",
    "            count = count+1\n",
    "        else:\n",
    "            print(\"猜那么多次都不对，你个笨蛋\")\n",
    "            print(\"正确答案是：%s\"%hide_card)\n",
    "            break\n",
    "else:\n",
    "            print(\"请输入数字在0-99之间，不要耍赖！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2599d4ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "if hide_card<100 and hide_card>0 :\n",
    "    print(\"游戏开始了\")\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_digit= int(input(\"guess_digit:\"))#玩游戏的人\n",
    "            if guess_digit ==hide_card:\n",
    "                print(\"yes,you got it.\")\n",
    "                break\n",
    "                elif guess_digit>hide_card:\n",
    "                    print(\"往小了猜一下\")\n",
    "                    else:\n",
    "                        print(\"往大了猜\")\n",
    "                        count = count+1\n",
    "                        else:\n",
    "                            print(\"猜那么多次都不对，你个笨蛋\")\n",
    "                            print(\"正确答案是：%s\"%hide_card)\n",
    "                            break\n",
    "                            else:\n",
    "                                print(\"请输入数字在0-99之间，不要耍赖！\")\n",
    "                        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4778187",
   "metadata": {},
   "source": [
    "# 购物车"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1eecf586",
   "metadata": {},
   "source": [
    "*购物车程序项目：\n",
    "> 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给客户\n",
    "> 2. 让用户输入商品编号进行商品购买\n",
    "> 3. 用户选择商品后，检查用户的余额是否够，若够直接扣款，不够则提醒用户\n",
    "> 4. 用户可以随时推出购买，退出时打印用户已购买的商品和支付宝余额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "f9f91af4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额100\n",
      "-------买小动物噜-------\n",
      "0 汪汪叫小狗 10元\n",
      "1 喵喵叫小猫 10元\n",
      "2 哞哞叫小牛 10元\n",
      "3 咩咩叫小羊 10元\n",
      "请输入商品编号1\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'user_choice' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-38-634e1a7a4b17>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     17\u001b[0m     \u001b[0muser_chioce\u001b[0m  \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入商品编号\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     18\u001b[0m     \u001b[1;31m# 3. 用户选择商品后，检查用户的余额是否够，若够直接扣款，不够则提醒用户\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m     \u001b[1;32mif\u001b[0m \u001b[0muser_choice\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0misdigit\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     20\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mAliPay\u001b[0m\u001b[1;33m>\u001b[0m\u001b[0mgood_list\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0muser_choice\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     21\u001b[0m             \u001b[1;31m#余额够\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'user_choice' is not defined"
     ]
    }
   ],
   "source": [
    "# 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给客户\n",
    "good_list = [\n",
    "    [\"汪汪叫小狗\",10],\n",
    "    [\"喵喵叫小猫\",10],\n",
    "    [\"哞哞叫小牛\",10],\n",
    "    [\"咩咩叫小羊\",10],\n",
    "]\n",
    "#数据存放，列表的增加(apped)\n",
    "shopping = []\n",
    "AliPay = int(input(\"请输入余额\"))\n",
    "\n",
    "while True:\n",
    "    print(\"-------买小动物噜-------\")\n",
    "    for i in range(4):\n",
    "        print(i,good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "    # 2. 让用户输入商品编号进行商品购买\n",
    "    user_chioce  = input(\"请输入商品编号:\")\n",
    "    # 3. 用户选择商品后，检查用户的余额是否够，若够直接扣款，不够则提醒用户\n",
    "    if user_choice.isdigit:\n",
    "        if AliPay>good_list[user_choice][1]:\n",
    "            #余额够\n",
    "            AliPay = AliPay - good_list[user_choice][1] #更新用户余额\n",
    "            shopping_list.append(good_list[user_choice])\n",
    "            print(\"购买成功啰!您的余额还有：%s元\"%(AliPay))\n",
    "    else:\n",
    "        #余额不够\n",
    "        print(\"55不够钱噢\")\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f5fa611",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "249ffc1d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c3d778f6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88be07ac",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77785840",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3150b3c1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78b34800",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
